using Microsoft.AspNetCore.Mvc;
using ZR.Service.Business.IBusinessService;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;

//创建时间：2024-09-29
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// 扫码信息
    /// </summary>
    [Verify]
    [Route("review/scaninfo")]
    [ApiExplorerSettings(GroupName = "business")]
    public class ScanInfoController : BaseController
    {
        /// <summary>
        /// 扫码信息接口
        /// </summary>
        private readonly IScanInfoService _ScanInfoService;

        public ScanInfoController(IScanInfoService ScanInfoService)
        {
            _ScanInfoService = ScanInfoService;
        }

        /// <summary>
        /// 查询扫码信息列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "review:scaninfo:list")]
        public IActionResult QueryScanInfo([FromQuery] ScanInfoQueryDto parm)
        {
            var response = _ScanInfoService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询扫码信息详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "review:scaninfo:query")]
        public IActionResult GetScanInfo(int Id)
        {
            var response = _ScanInfoService.GetInfo(Id);

            var info = response.Adapt<ScanInfoDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加扫码信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "review:scaninfo:add")]
        [Log(Title = "扫码信息", BusinessType = BusinessType.INSERT)]
        public IActionResult AddScanInfo([FromBody] ScanInfoDto parm)
        {
            var modal = parm.Adapt<ScanInfo>().ToCreate(HttpContext);

            var response = _ScanInfoService.AddScanInfo(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新扫码信息
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "review:scaninfo:edit")]
        [Log(Title = "扫码信息", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateScanInfo([FromBody] ScanInfoDto parm)
        {
            var modal = parm.Adapt<ScanInfo>().ToUpdate(HttpContext);
            var response = _ScanInfoService.UpdateScanInfo(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除扫码信息
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "review:scaninfo:delete")]
        [Log(Title = "扫码信息", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteScanInfo([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_ScanInfoService.Delete(idArr));
        }
    }
}